import {$get} from "@/utils/api/getApi";
import '@/utils/request.js'

// 获取违章信息
export const getViolationList = (query) => {
    //vehicleId，orderId 参数
    return $get('/vehicle/violation/list', query)
}

export const getlistrec = (data) => {
    return $get('/vehicle/goods/list', data)
}

// export const selectCarsBySchedule = (data) => {
//     return $get('/wechat/goods/selectCarsBySchedule', data)
// }

export const getPassengerList = (data) => {
    return $get('/vehicle/passenger/list', data)
}

export const addPassenger = (data) => {
    return uni.$post('/vehicle/passenger', data)
}

export const editPassenger = (data) => {
    return uni.$put('/vehicle/passenger', data)
}
export const editWechat = (data) => {
    return uni.$put('/wechat/customer', data)
}

export const delPassenger = (data) => {
    return uni.$delete('/vehicle/passenger/' + data)
}

export const queryScore = (data) => {
    return $get('/busscomment/comment/getTotalScore', data)
}

// 查询评论列表方法
export const queryCommentList = (data) => {
    return $get('/busscomment/comment/list', data)
}
// 添加评论方法
export const addComment = (data) => {
    return uni.$post('/busscomment/comment', data)
}

export const cancelOrder = (data) => {
    return uni.$get("/wechat/vehorder/cancelOrder/" + data)
}


export const payOrder = (data) => {
    return uni.$post("/wechat/vehorder/payOrder", data)
}

// 验证码校验
export const verificationCode = (data) => {
    return $post('/wechat/verification/verificationCode', data)
}

// 发送手机验证码
export const sendMsg = (data) => {
    return $post('/wechat/verification/sendCode', data)
}

// 获取车辆信息
export const publicVehicleGoods = (code) => {
    return uni.$get('/merchant/public/vehicle/' + code)
}


export const getWxConfig = () => {
    return uni.$get(`/wechat/customer/wxConfig/${uni.getAccountInfoSync().miniProgram.appId}`)
}

export const $post = (url, data) => {
    if (typeof data === 'string') {
        url += '?'
    } else if (typeof data === 'object') {
        // 参数为对象格式
        const arr = []
        //通过for in 循环将对象格式转化成a=1&b=2格式的字符串
        for (const key in data) {
            if (data[key] != undefined) {
                arr.push(`${key}=${data[key]}`)
            }
        }
        if (arr.length > 0) {
            url += '?' + arr.join("&")
        }
    }
    return uni.$post(url)
}